﻿$(document).ready(function () {
    //Initialization
    SetTextBoxIdentityCard();
    SetCheckBoxIsEmployee();
    SetCheckBoxIsVisaForeigner();
    SetPatientRelative();
    SetSpouseName();

    ///TextBoxGender
    $("#SalutationId").change(
        function () {
            if ($("#SalutationId").val() == 1) {
                $("#gender").val("Male");
            } else if ($("#SalutationId").val() == 2) {
                $("#gender").val("Female");
            } else {
                $("#gender").val("");
            }
            $("#GenderId").val($("#SalutationId").val());
        }
    );

    ///TextBoxAge
    function getYesterdayDate() {
        var date = new Date;
        date.setDate(date.getDate() - 1);
        return date;
    }
    $("#TextBoxDob").datepicker({
        showOtherMonths: true,
        dateFormat: "dd/mm/yy",
        changeYear: true,
        changeMonth: true,
        maxDate: getYesterdayDate(),
        yearRange: "-70:+0",
        onSelect: function (dateStr) {
            $('#mws-validate').validate().element(this);
            $("#TextBoxAge").val(getAge($("#TextBoxDob").val()));
        }
    });
    $("#TextBoxDob").blur(function () {
        if ($("#TextBoxDob").val() != "") {
            $("#TextBoxAge").val(getAge($("#TextBoxDob").val()));
        }

    });
    //End TextBoxAge

    //CheckBox IsEmployee
    $("#CheckBoxPrimaryIsEmployee").click(function () {
        if (this.checked) {
            $("#HiddenPrimaryIsEmployee").val("1");
            $("#PrimaryPayerEmployeeId").attr("readonly", false);
        } else {
            $("#HiddenPrimaryIsEmployee").val("0");
            $("#PrimaryPayerEmployeeId").attr("readonly", true);
            $("#PrimaryPayerEmployeeId").val("");
        }

    });
    $("#CheckBoxSecondaryIsEmployee").click(function () {
        if (this.checked) {
            $("#HiddenSecondaryIsEmployee").val("1");
            $("#SecondaryPayerEmployeeId").attr("readonly", false);
        } else {
            $("#HiddenSecondaryIsEmployee").val("0");
            $("#SecondaryPayerEmployeeId").attr("readonly", true);
            $("#SecondaryPayerEmployeeId").val("");
        }

    });
    $("#CheckBoxTertieryIsEmployee").click(function () {
        if (this.checked) {
            $("#HiddenTertieryIsEmployee").val("1");
            $("#TertieryPayerEmployeeId").attr("readonly", false);
        } else {
            $("#HiddenTertieryIsEmployee").val("0");
            $("#TertieryPayerEmployeeId").attr("readonly", true);
            $("#TertieryPayerEmployeeId").val("");
        }

    });

    //DropDown Private Payer
    $("#PrimaryPayerCategoryId").blur(
        function () {
            SetTextBoxPrimaryPayer();
        }
     );
    $("#SecondaryPayerCategoryId").blur(
        function () {
            SetTextBoxSecondaryPayer();
        }
    );
    $("#TertieryPayerCategoryId").blur(
        function () {
            SetTextBoxTertieryPayer();
        }
    );
    $("#FamilyRelativeName").blur(function () {
        SetPatientRelative();
    });
    $("#OtherRelativeName").blur(function () {
        SetPatientRelative();
    });


    function SetCheckBoxIsEmployee() {
        if ($("#PrimaryPayerEmployeeId").val() != "") {
            $("#CheckBoxPrimaryIsEmployee").attr("checked", true);
        }
        if ($("#SecondaryPayerEmployeeId").val() != "") {
            $("#CheckBoxSecondaryIsEmployee").attr("checked", true);
        }
        if ($("#TertieryPayerEmployeeId").val() != "") {
            $("#CheckBoxTertieryIsEmployee").attr("checked", true);
        }

    }
    function SetPatientRelative() {
        if ($("#FamilyRelativeName").val() == "") {
            $("#FamilyRelativeTypeId").rules("remove");
            $("#FamilyRelativeAddress").rules("remove");
        } else {
            $("#FamilyRelativeTypeId").rules("add", { required: true });
            $("#FamilyRelativeAddress").rules("add", { required: true });
        }
        if ($("#OtherRelativeName").val() == "") {
            $("#OtherRelativeTypeId").rules("remove");
            $("#OtherRelativeAddress").rules("remove");
        } else {
            $("#OtherRelativeTypeId").rules("add", { required: true });
            $("#OtherRelativeAddress").rules("add", { required: true });
        }

    }
    ///GetDateTime clock client side update
    var serverDate;
    function getServerDate() {
        $.get(rooturl + "frontofficeregistration/getclock", function (result) {
            serverDate = new Date(Date.parse(result));
        });
    }
    function tick() {
        if (serverDate) {
            serverDate.setSeconds(serverDate.getSeconds() + 1);
            var min = serverDate.getMinutes();
            if (min < 10) min = "0" + min;
            var sec = serverDate.getSeconds();
            if (sec < 10) sec = "0" + sec;
            var month = serverDate.getMonth() + 1;
            var clock = serverDate.getDate() + "-" + month + "-" + serverDate.getFullYear() + "  " + serverDate.getHours() + ":" + min + ":" + sec;
            $('#reg_time').val(clock);
        }
    }

    $(function () {
        if (window.location == rooturl + "frontoffice/registration/register") {
            getServerDate();
            setInterval(tick, 1000);
        }

    });


    ///OnCheck CheckBox Same as Present Address
    $("#CheckboxPermanentAddress").click(function () {
        if (this.checked) {
            $("#TextBoxAddressDescPermanent").val($("#TextBoxAddressDescPresent").val());
            $("#TextBoxAreaPermanent").val($("#TextBoxAreaPresent").val());
            $("#TextBoxCityPermanent").val($("#TextBoxCityPresent").val());
            $("#TextBoxStatePermanent").val($("#TextBoxStatePresent").val());
            $("#TextBoxCountryPermanent").val($("#TextBoxCountryPresent").val());
            $("#TextBoxZipCodePermanent").val($("#TextBoxZipCodePresent").val());
            $("#TextBoxPhoneNumberPermanent").val($("#TextBoxPhoneNumberPresent").val());

            $("#HiddenPermanentAddressAreaId").val($("#HiddenPresentAddressAreaId").val());
            $("#HiddenPermanentAddressCityId").val($("#HiddenPresentAddressCityId").val());
            $("#HiddenPermanentAddressCountryId").val($("#HiddenPresentAddressCountryId").val());
            $("#HiddenPermanentProvinceId").val($("#HiddenPresentProvinceId").val());
        } else {
            ResetPermanentAddress();
        }

    });


    //IdentityCard
    //Flag
    $("#IdentityCardTypeId").change(
        function () {
            SetTextBoxIdentityCard();
            $("#IdentityCardbNumber").val("");
        }
    );

    function SetTextBoxIdentityCard() {
        if ($("#IdentityCardTypeId").val() == 3) {
            $("#divIdentityCardbNumber").removeClass("mws-form-col-5-8");
            $("#divButtonPassportDetail").css({ display: "block" });
            $("#divIdentityCardbNumber").addClass("mws-form-col-3-8"); style = "width:211px"
            $("#IdentityCardbNumber").css({ width: "125px" });
        } else {
            $("#divIdentityCardbNumber").removeClass("mws-form-col-3-8");
            $("#divIdentityCardbNumber").addClass("mws-form-col-5-8");
            $("#divButtonPassportDetail").css({ display: "none" });
            $("#IdentityCardbNumber").css({ width: "211px" });
        }
    }

    //SpouseName
    $("#MaritalId").change(
        function () {
            SetSpouseName();
        }
    );
    function SetSpouseName() {
        if ($("#MaritalId").val() == 1) {
            $("#SpouseName").attr("disabled", true);
        } else {
            $("#SpouseName").attr("disabled", false);
        }
    }

    function OpenPopupConfirm() {
        $("#dialog:ui-dialog").dialog("destroy");

        $("#dialog-confirm").dialog({
            resizable: false,
            //autoOpen: false,
            height: 160,
            modal: true,
            buttons: {
                "Yes": function () {
                    window.location = rooturl + "frontoffice/registration/registrationnextstep";
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
        });
    }


    //passport
    $("#mws-validate-passport").validate({});
    
    $("#passportDialog").dialog({
        width: 1200,
        zIndex: 5,
        modal: true,
        autoOpen: false,
        title:"Passport Detail",
        dialogClass: 'no-close'
    });
    

    $("#buttonSubmitPassport").click(
            function () {
                if ($("#mws-validate-passport").valid() == true) {
                    SetPassport();
                    $("#passportDialog").dialog("close");
                    $("#IdentityCardbNumber").val($("#TextBoxPassport").val());
                    $('#mws-validate').validate().element($("#IdentityCardbNumber"));
                }
            }
        );
    $("#buttonCancelPassport").click(
            function () {
                $("#passportDialog").dialog("close");
            }
       );


    $("#CheckBoxVisaForeigner").click(function () {
        if (this.checked) {
            $("#VisaIsForeigner").val("1");
        } else {
            $("#VisaIsForeigner").val("0");
        }
    });
    function SetCheckBoxIsVisaForeigner() {
        if ($("#VisaIsForeigner").val() == "1") {
            $("#CheckBoxVisaForeigner").attr("checked", true);
        }
        if ($("#VisaIsForeigner").val() == "0") {
            $("#CheckBoxVisaForeigner").attr("checked", false);
        }

    }
    //End passport

    //Submit Form Ajax
    $("#mws-validate").submit(
        function () {
            if ($("#mws-validate").valid() == true) {
                //$.blockUI({
                //    message: $("#ajaxLoader")
                //});
                $.blockUI();
                var post_data = $(this).serialize();
                var form_action = $(this).attr("action");
                var form_method = $(this).attr("method");
                $.ajax({
                    type: form_method,
                    url: form_action,
                    cache: false,
                    dataType: "json",
                    data: post_data,
                    success: function (data) {
                        window.scrollTo(0, 0);
                        $.unblockUI();
                        $("#notif").html(data['strNotification']);
                        $("#MedicalRecordNumber").val(data['mrn']);
                        $("#PatientId").val(data['patientId']);
                        $("#HiddenPresentAddressId").val(data['HiddenPresentAddressId']);
                        $("#HiddenPermanentAddressId").val(data['HiddenPermanentAddressId']);
                        $("#PrimaryPayerId").val(data['PrimaryPayerId']);
                        $("#SecondaryPayerId").val(data['SecondaryPayerId']);
                        $("#TertieryPayerId").val(data['TertieryPayerId']);
                        $("#FatherId").val(data['FatherId']);
                        $("#MotherId").val(data['MotherId']);
                        $("#SpouseId").val(data['SpouseId']);
                        $("#FamilyRelativeId").val(data['FamilyRelativeId']);
                        $("#OtherRelativeId").val(data['OtherRelativeId']);
                        if (data['strNotification'] != null) {
                            OpenPopupConfirm();
                        }
                    },
                    error: function () {
                        alert("Error Occured While Saving Data");
                        $.unblockUI();
                    },
                    complete: function () {

                    }
                });
            } else {
                if ($("#TextBoxAddressDescPresent").is('.error') || $("#PhoneNumber").is('.error')) {
                    $(".mws-accordion").accordion("option", "active", 0);
                } else if ($("#PrimaryPayerCategoryId").is('.error')) {
                    $(".mws-accordion").accordion("option", "active", 2);
                } else if ($("#FamilyRelativeAddress").is('.error') || $("#FamilyRelativeTypeId").is('.error')) {
                    $(".mws-accordion").accordion("option", "active", 3);
                } else if ($("#OtherRelativeAddress").is('.error') || $("#OtherRelativeTypeId").is('.error')) {
                    $(".mws-accordion").accordion("option", "active", 4);
                }
            }
            return false;
        });

    //Validation
    $("#FirstName, #MiddleName, #LastName").each(function () {
        $(this).rules("add", {
            maxlength: 15
        });
    });
    $("#IdentityCardbNumber").rules("add", {
        maxlength: 30
    });
    $("#TextBoxZipCodePresent, #TextBoxZipCodePermanent").each(function () {
        $(this).rules("add", {
            maxlength: 10
        });
    });
    jQuery.validator.addMethod("regexWeight", function (value, element) {
        if (value < 1000) {
            return this.optional(element) || /^\d*\.?\d{0,2}$/.test(value);
        } else {
            return false;
        }
    }, "Please enter a valid weight"
    );
    jQuery.validator.addMethod("regexHeight", function (value, element) {
        if (value < 1000) {
            return this.optional(element) || /^\d*\.?\d{0,2}$/.test(value);
        } else {
            return false;
        }
    }, "Please enter a valid height"
    );
    $("#Weight").rules("add", {
        regexWeight: true
    });
    $("#Height").rules("add", {
        regexHeight: true
    });
    //End Validation

});
//End Document.ready

///FileUpload
$(function () {
    new AjaxUpload('#uploadFile', {
        action: rooturl + 'patientdata/default/uploadhandler',
        name: 'upload',
        onComplete: function (file,data) {
            $('#fileList').html('<div><img src="' + rooturl + 'Images/PatientImages/' + data + '" style="height:175px;width:150px;"/> </div>');
            $('#uploadStatus').html('');
        },
        onSubmit: function (file, ext) {
            if (!(ext && /^(gif|jpeg|png|jpg|bmp)$/i.test(ext))) {
                alert('Invalid File Format.');
                return false;
            }
            $('#uploadStatus').html('<img src="' + rooturl + 'Images/Icons/ajax-loader.gif" style="height:30px;width:100px;" />');
        }
    });
});


//Popup Area Address
function OpenPopUpPresentArea(url) {
    $("#HiddenIsPermanentAddress").val("0");
    $("#mws-form-dialog").dialog("open");
    $("#modalIframeForm").attr("src", rooturl + "home/popup/popupsearcharea");
    return false;
}
function OpenPopUpPermanentArea(url) {
    $("#HiddenIsPermanentAddress").val("1");
    $("#mws-form-dialog").dialog("open");
    $("#modalIframeForm").attr("src", rooturl + "home/popup/popupsearcharea");
    return false;
}

function IsPermanentAddress() {
    return $("#HiddenIsPermanentAddress").val();
}

function setAreaTextBox(AreaId, AreaName, CityId, CityName, CountryId, CountryName, ProvinceId, ProvinceName) {
    if (parent.IsPermanentAddress() == "0") {
        parent.setPresentAreaTextBox(AreaId, AreaName, CityId, CityName, CountryId, CountryName, ProvinceId, ProvinceName);
    } else {
        parent.setPermanentAreaTextBox(AreaId, AreaName, CityId, CityName, CountryId, CountryName, ProvinceId, ProvinceName);
    }
}

function setPresentAreaTextBox(AreaId, AreaName, CityId, CityName, CountryId, CountryName, ProvinceId, ProvinceName) {
    $("#TextBoxAreaPresent").val(AreaName);
    $("#HiddenPresentAddressAreaId").val(AreaId);
    $("#HiddenPresentAddressCityId").val(CityId);
    $("#TextBoxCityPresent").val(CityName);
    $("#TextBoxStatePresent").val(ProvinceName);
    $("#HiddenPresentAddressCountryId").val(CountryId);
    $("#TextBoxCountryPresent").val(CountryName);
    $("#HiddenPresentProvinceId").val(ProvinceId);
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");

}
function setPermanentAreaTextBox(AreaId, AreaName, CityId, CityName, CountryId, CountryName, ProvinceId, ProvinceName) {
    $("#TextBoxAreaPermanent").val(AreaName);
    $("#HiddenPermanentAddressAreaId").val(AreaId);
    $("#HiddenPermanentAddressCityId").val(CityId);
    $("#TextBoxCityPermanent").val(CityName);
    $("#TextBoxStatePermanent").val(ProvinceName);
    $("#HiddenPermanentAddressCountryId").val(CountryId);
    $("#TextBoxCountryPermanent").val(CountryName);
    $("#HiddenPermanentProvinceId").val(ProvinceId);
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");
}
function ResetPermanentAddress() {
    $("#TextBoxAddressDescPermanent").val("");
    $("#TextBoxAreaPermanent").val("");
    $("#TextBoxCityPermanent").val("");
    $("#TextBoxStatePermanent").val("");
    $("#TextBoxCountryPermanent").val("");
    $("#TextBoxZipCodePermanent").val("");
    $("#TextBoxPhoneNumberPermanent").val("");
    $("#HiddenPermanentAddressAreaId").val("");
    $("#HiddenPermanentAddressCityId").val("");
    $("#HiddenPermanentAddressCountryId").val("");
    $("#HiddenPermanentProvinceId").val("");
    $("#CheckboxPermanentAddress").attr("checked", false);
}
function ResetPresentAddress() {
    $("#TextBoxAddressDescPresent").val("");
    $("#TextBoxAreaPresent").val("");
    $("#TextBoxCityPresent").val("");
    $("#TextBoxStatePresent").val("");
    $("#TextBoxCountryPresent").val("");
    $("#TextBoxZipCodePresent").val("");
    $("#TextBoxPhoneNumberPresent").val("");
    $("#HiddenPresentAddressAreaId").val("");
    $("#HiddenPresentAddressCityId").val("");
    $("#HiddenPresentAddressCountryId").val("");
    $("#HiddenPresentProvinceId").val("");
}

//Popup Confirm
function OpenPopUpRegNextStep() {
    $("#mws-form-dialog").dialog("open");
    $("#modalIframeForm").attr("src", rooturl + "home/popup/popupregistrationnextstep");
    return false;
}

//passport

function OpenPopUpPassportDetail() {
    $("#mws-form-dialog").dialog("open");
    $("#modalIframeForm").attr("src", rooturl + "home/popup/popuppassportdetail");
    return false;
}

function SetPassport() {
    $("#HiddenPassportId").val($("#PassportId").val());
    $("#HiddenPatientPassportTypeId").val($("#PatientPassportTypeId").val());
    $("#PassportCodeValue").val($("#TextBoxPassport").val());
    $("#PassportIssuedDate").val($("#TextBoxPassportIssuedDate").val());
    $("#PassportExpiryDate").val($("#TextBoxPassportExpiryDate").val());
    $("#PassportIssuedAt").val($("#TextBoxPassportIssuedAt").val());
    $("#HPassportNationality").val($("#PassportNationality").val());

    $("#HiddenVisaId").val($("#VisaId").val());
    $("#HiddenPatientVisaTypeId").val($("#PatientVisaTypeId").val());
    $("#VisaIssuedMe").val($("#TextBoxVisaIssuedMe").val());
    $("#VisaIssuedDate").val($("#TextBoxVisaIssuedDate").val());
    $("#VisaExpiryDate").val($("#TextBoxVisaExpiryDate").val());
    $("#VisaIssuedBy").val($("#TextBoxVisaIssuedBy").val());
    $("#HiddenVisaIsForeigner").val($("#VisaIsForeigner").val());

    $("#HiddenWorkPermitId").val($("#WorkPermitId").val());
    $("#HiddenPatientWorkPermitTypeId").val($("#PatientWorkPermitTypeId").val());
    $("#WorkPermitCodeValue").val($("#TextBoxWorkPermitId").val());
    $("#WorkPermitIssuedDate").val($("#TextBoxWorkPermitIssuedDate").val());
    $("#WorkPermitExpiryDate").val($("#TextBoxWorkPermitExpiryDate").val());
    $("#WorkPermitIssuedBy").val($("#TextBoxWorkPermitIssuedBy").val());    

}

function ResetPassport() {
    $("#IdentityCardbNumber").val("");
    $("#TextBoxPassport").val("");
    $("#TextBoxPassportIssuedDate").val("");
    $("#TextBoxPassportExpiryDate").val("");
    $("#TextBoxPassportIssuedAt").val();
    $("#DdPassportNationality").val("");
    $("#TextBoxVisaIssuedMe").val("");
    $("#TextBoxVisaIssuedDate").val("");
    $("#TextBoxVisaExpiryDate").val("");
    $("#TextBoxVisaIssuedBy").val("");
    $("#CheckBoxVisaForeigner").val("");
    $("#TextBoxWorkPermitId").val("");
    $("#TextBoxWorkPermitIssuedDate").val("");
    $("#TextBoxWorkPermitExpiryDate").val("");
    $("#TextBoxWorkPermitIssuedBy").val("");
}


function CloseDialog() {
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");
}


function ResetFamilyRelative() {
    $("#FamilyRelativeName").val("");
    $("#FamilyRelativeAddress").val("");
    $("#FamilyRelativePhone").val("");
    $("#FamilyRelativeMobilephone").val("");
    $("#FamilyRelativeEmail").val("");
    $("#FamilyRelativeTypeId").val("");
    $("#FamilyRelativeNote").val("");

    $("#FamilyRelativeTypeId").rules("remove");
    $("#FamilyRelativeAddress").rules("remove");
}
function ResetOtherRelative() {
    $("#OtherRelativeName").val("");
    $("#OtherRelativeAddress").val("");
    $("#OtherRelativePhone").val("");
    $("#OtherRelativeMobilephone").val("");
    $("#OtherRelativeEmail").val("");
    $("#OtherRelativeTypeId").val("");
    $("#OtherRelativeNote").val("");

    $("#OtherRelativeTypeId").rules("remove");
    $("#OtherRelativeAddress").rules("remove");
}
function ResetPrimaryPayer() {
    $("#PrimaryPayerCategoryId").val("0");
    $("#PrimaryPayerCategoryName").val("");
    $("#PrimaryPayerName").val("");
    $("#PrimaryPayerPhoneNumber").val("");
    $("#PrimaryPayerValidFrom").val("");
    $("#PrimaryPayerValidTo").val("");
    $("#PrimaryPayerInsuranceNumber").val("");
    $("#PrimaryPayerFax").val("");

    $("#PrimaryPayerAddressDesc").val("");
    $("#CheckBoxPrimaryIsEmployee").attr("checked", false);
    $("#HiddenPrimaryIsEmployee").val("0");
    $("#PrimaryPayerEmployeeId").val("");

}
function ResetSecondaryPayer() {
    $("#SecondaryPayerCategoryId").val("0");
    $("#SecondaryPayerCategoryName").val("");
    $("#SecondaryPayerName").val("");
    $("#SecondaryPayerPhoneNumber").val("");
    $("#SecondaryPayerValidFrom").val("");
    $("#SecondaryPayerValidTo").val("");
    $("#SecondaryPayerInsuranceNumber").val("");
    $("#SecondaryPayerFax").val("");

    $("#SecondaryPayerAddressDesc").val("");
    $("#CheckBoxSecondaryIsEmployee").attr("checked", false);
    $("#HiddenSecondaryIsEmployee").val("0");
    $("#SecondaryPayerEmployeeId").val("");

}
function ResetTertieryPayer() {
    $("#TertieryPayerCategoryId").val("0");
    $("#TertieryPayerCategoryName").val("");
    $("#TertieryPayerName").val("");
    $("#TertieryPayerPhoneNumber").val("");
    $("#TertieryPayerValidFrom").val("");
    $("#TertieryPayerValidTo").val("");
    $("#TertieryPayerInsuranceNumber").val("");
    $("#TertieryPayerFax").val("");

    $("#TertieryPayerAddressDesc").val("");
    $("#CheckBoxTertieryIsEmployee").attr("checked", false);
    $("#HiddenTertieryIsEmployee").val("0");
    $("#TertieryPayerEmployeeId").val("");

}

///Flag

function OpenPopUpPrimaryPayer() {
    OpenPopupPatientPayer();
    $("#HiddenPayerStatus").val("0");
}
function OpenPopUpSecondaryPayer() {
    OpenPopupPatientPayer();
    $("#HiddenPayerStatus").val("1");
}
function OpenPopUpTertieryPayer() {
    OpenPopupPatientPayer();
    $("#HiddenPayerStatus").val("2");
}
function OpenPopupPatientPayer() {
    $("#mws-form-dialog").dialog("open");
    $("#modalIframeForm").attr("src", rooturl + "home/popup/popupsearchpayer");
    return false;
}
function PayerStatus() {
    return $("#HiddenPayerStatus").val();
}

function SetPatientPayer(PayerId,PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName) {
    if (parent.PayerStatus() == "0") {
        parent.setPrimaryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName);
    } else if (parent.PayerStatus() == "1") {
        parent.setSecondaryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName);
    } else if (parent.PayerStatus() == "2") {
        parent.setTertieryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName);
    }
}

function setPrimaryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName) {
    $("#HiddenPrimaryBankInsuranceId").val(PayerId);
    $("#PrimaryPayerCategoryId").val(PayerCategory);
    $("#PrimaryPayerCategoryName").val(CategoryName);
    $("#PrimaryPayerName").val(PayerName);
    $("#PrimaryPayerPhoneNumber").val(PayerPhone);
    $("#PrimaryPayerFax").val(PayerFax);
    $("#PrimaryPayerAddressDesc").val(PayerAddress);
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");

}
function setSecondaryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName) {
    $("#HiddenSecondaryBankInsuranceId").val(PayerId);
    $("#SecondaryPayerCategoryId").val(PayerCategory);
    $("#SecondaryPayerCategoryName").val(CategoryName);
    $("#SecondaryPayerName").val(PayerName);
    $("#SecondaryPayerPhoneNumber").val(PayerPhone);
    $("#SecondaryPayerFax").val(PayerFax);
    $("#SecondaryPayerAddressDesc").val(PayerAddress);
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");
}
function setTertieryPayer(PayerId, PayerCategory, PayerName, PayerPhone, PayerFax, PayerAddress, CategoryName) {
    $("#HiddenTertieryBankInsuranceId").val(PayerId);
    $("#TertieryPayerCategoryId").val(PayerCategory);
    $("#TertieryPayerCategoryName").val(CategoryName);
    $("#TertieryPayerName").val(PayerName);
    $("#TertieryPayerPhoneNumber").val(PayerPhone);
    $("#TertieryPayerFax").val(PayerFax);
    $("#TertieryPayerAddressDesc").val(PayerAddress);
    $('#modalIframeForm').attr('src', '');
    $("#mws-form-dialog").dialog("close");
}

//flags
function OpenPopUpPassportDetail2() {
    $("#passportDialog").dialog("open");
    $('#mws-validate-passport').validate().element("#TextBoxPassportIssuedDate");
    $('#mws-validate-passport').validate().element("#TextBoxPassportExpiryDate");
    $('#mws-validate-passport').validate().element("#TextBoxVisaIssuedDate");
    $('#mws-validate-passport').validate().element("#TextBoxVisaExpiryDate");
    $('#mws-validate-passport').validate().element("#TextBoxWorkPermitIssuedDate");
    $('#mws-validate-passport').validate().element("#TextBoxWorkPermitExpiryDate");
}